package com.cims.action.order;

import java.util.ArrayList;
import java.util.List;

import com.cims.action.BaseAction;
import com.cims.bo.order.OrderItemBO;
import com.cims.bo.order.OrderItemBOImpl;
import com.cims.bo.staff.StaffBO;
import com.cims.bo.staff.StaffBOImpl;
import com.cims.bo.task.TaskBO;
import com.cims.bo.task.TaskBOImpl;
import com.cims.common.OrderItemExtend;
import com.cims.common.exception.BoException;
import com.cims.common.vo.OrderItem;
import com.cims.common.vo.Staff;
import com.cims.common.vo.Task;
import com.cims.common.vo.User;

public class OrderItemAction extends BaseAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = 6316367989549748996L;
	private OrderItemBO order = new OrderItemBOImpl();
	private List<OrderItem> listOrderItem = new ArrayList<OrderItem>();
	private List<String> symptomCheckBoxList = new ArrayList<String>();
	private List<Staff> listStaff = new ArrayList<Staff>();
	private String selectedStaff;
	
	public List<Staff> getListStaff() {
		return listStaff;
	}

	public void setListStaff(List<Staff> listStaff) {
		this.listStaff = listStaff;
	}

	public String getSelectedStaff() {
		return selectedStaff;
	}

	public void setSelectedStaff(String selectedStaff) {
		this.selectedStaff = selectedStaff;
	}

	
	public List<Staff> queryListStaff() {
		StaffBO sbo = new StaffBOImpl();
		try {
			List<Staff> temp =  sbo.getListStaff();
			return temp;

		} catch (Exception e) {
			// TODO: handle exception
		}
		return null;
	}

	public List<String> getSymptomCheckBoxList() {
		return symptomCheckBoxList;
	}

	public void setSymptomCheckBoxList(List<String> symptomCheckBoxList) {
		this.symptomCheckBoxList = symptomCheckBoxList;
	}

	// list all order
	public String list() {
		try {
			setListStaff(queryListStaff());
			listOrderItem = order.getListOrderUnAssigned();

		} catch (Exception e) {
			// TODO: handle exception
		}
		return SUCCESS;
	}
	
	public String listAllOrder() {
		try {
			//setListStaff(queryListStaff());
			listOrderItem = order.getListOrder();

		} catch (Exception e) {
			// TODO: handle exception
		}
		return SUCCESS;
	}


	public List<OrderItem> getListOrderItem() {
		return listOrderItem;
	}

	public void setListOrderItem(List<OrderItem> listOrderItem) {
		this.listOrderItem = listOrderItem;
	}

	public OrderItemBO getOrderItemBO() {
		return order;
	}

	public void setOrderItemBO(OrderItemBO order) {
		this.order = order;
	}


	public void test() {
		for(String r : symptomCheckBoxList) {
			System.err.println(r);
		}
		
		System.err.println("Selected value = " + selectedStaff);
	}
	
	public void AssignTask() {
		Boolean check = false;
		for(String orderId : symptomCheckBoxList) {
			check = assignOrderToStaff(Integer.parseInt(orderId), Integer.parseInt(selectedStaff));
		}
		
		System.err.print(check.toString());
	}
	
	private Boolean assignOrderToStaff(int orderId, int staffId) {
		TaskBO tbo = new TaskBOImpl();
		Task tmp = new Task();
		OrderItem otmp = new OrderItem();
		otmp.setOrderId(orderId);
		Staff stmp = new Staff();
		stmp.setStaffId(staffId);
		
		tmp.setOrderItem(otmp);
		tmp.setStaff(stmp);
		
		try {
			return tbo.insert(tmp);
		} catch (BoException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return false;
		
	
	}
}
